package com.zb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjAdmVersionModule;
import com.zb.mapper.ZjAdmVersionModuleMapper;
import com.zb.service.ZjAdmVersionModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 后台版本模块关联表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-07-12
 */
@Service
public class ZjAdmVersionModuleServiceImpl extends ServiceImpl<ZjAdmVersionModuleMapper, ZjAdmVersionModule> implements ZjAdmVersionModuleService {
    @Autowired
    private ZjAdmVersionModuleMapper admVersionModuleMapper;

    // 新增或更改版本模块
    @Override
    public void save(Long versionId, List<Long> moduleIds) {
        admVersionModuleMapper.removeByVersionId(versionId);

        if (moduleIds.isEmpty()) {
            return;
        }

        List<ZjAdmVersionModule> modules = new ArrayList<>();
        ZjAdmVersionModule versionModule = null;
        for (Long moduleId : moduleIds) {
            versionModule = new ZjAdmVersionModule();
            versionModule.setModuleId(moduleId);
            versionModule.setVersionId(versionId);
            modules.add(versionModule);
        }
        this.saveBatch(modules);
    }

    // 根据版本ID查询模块
    @Override
    public List<String> getModuleByVersionId(Long versionId) {
        return admVersionModuleMapper.getModuleByVersionId(versionId);
    }

    // 根据版本ID查询模块ID集合
    @Override
    public List<Long> getModuleIdByVersionId(Long versionId) {
        return admVersionModuleMapper.getModuleIdByVersionId(versionId);
    }
}
